package com.bgs.travelapp.fileManager.controller;

import com.bgs.travelapp.fileManager.service.FileManagerService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@CrossOrigin
/**
 * 上传and下载图片
 * hbx 2022年8月4日09:37:18
 */
public class FileManagerController {
    @Resource
    FileManagerService fileManagerService;


    /**
     *批量图片上传
     * @param multipartRequest
     * @return
     */
    @PostMapping("uploadPicture")
    public Integer uploadPicture(MultipartRequest multipartRequest){
        MultipartFile file = multipartRequest.getFile("files");
        return  fileManagerService.uploadPicture(file);
    }

    /**
     * 从数据库下载图片根据id
     * @param id
     * @param response
     */
    @GetMapping("getImageById")
    public void getImageById(Integer id, HttpServletResponse response){
        fileManagerService.getImageById(response,id);
    }


    /**
     * 游记封面图片上传
     * hbx 2022年8月4日09:43:02
     * @param multipartRequest
     * @return
     */
    @PostMapping("uploadReicText")
    public Integer uploadReicText(MultipartRequest multipartRequest){
        return  fileManagerService.uploadReicText(multipartRequest);
    }


}
